<template>
	<view class="container">
		<view class="list-cell b-b " @click="navTo(`/pageA/setMobile/setMobile?mobile=${userInfo.mobile}`)"
			hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">手机号</text>
			<text class="cell-tip">{{userInfo.mobile}}</text>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view class="list-cell b-b " @click="handleWeixin" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">微信</text>
			<text class="cell-tip">{{ msg }} </text>
		</view>
		<!-- #endif -->
		<view class="list-cell  b-b" @click="navTo('/pageA/authentication/authentication')" hover-class="cell-hover"
			:hover-stay-time="50">
			<text class="cell-tit">实名认证</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell   b-b " @click="navTo('/pageA/makemode/makemode')" hover-class="cell-hover"
			:hover-stay-time="50">
			<text class="cell-tit">收款方式</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell   b-b " @click="navTo('/pageA/Security/Security')" hover-class="cell-hover"
			:hover-stay-time="50">
			<text class="cell-tit">密保设置</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell   b-b " @click="navTo('/pageA/loginPass/loginPass')" hover-class="cell-hover"
			:hover-stay-time="50">
			<text class="cell-tit">修改登录密码</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell   b-b " @click="navTo('/pageA/loginPass/payPass')" hover-class="cell-hover"
			:hover-stay-time="50">
			<text class="cell-tit">修改支付密码</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				userInfo: {},
				version: '',
				msg: '未绑定'
			};
		},
		onShow() {
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, async (inf) => {
				this.version = 'V' + inf.version
				console.log('当前版本', inf.version);
			})
			// #endif
			this.getInfo()
		},
		methods: {
			...mapMutations(['logout']),
			handleWeixin() {
				if (this.userInfo.openid) return
				const that = this
				uni.login({
					"provider": "weixin",
					"onlyAuthorize": true, // 微信登录仅请求授权认证
					success(res) {
						const {
							errMsg,
							code
						} = res
						if (errMsg == 'login:ok') {
							that.$fun.ajax.post('user/thirdwx', {
								code
							}).then((result) => {
								const {
									code,
									msg
								} = result
								if (code === 1) {
									that.$fun.msg(msg)
									that.msg = '已绑定'
								} else {
									that.$fun.msg(msg)
								}
							})
						}
					}
				})
			},
			account_change() {
				uni.navigateTo({
					url: '/pages/changeAccount/changeAccount'
				})
			},
			navTo(url) {
				if (url == 'cancellation') {
					uni.showModal({
						content: '注销账号后,账户相关信息将不可试用是否注销',
						success: (e) => {
							if (e.confirm) {
								this.$fun.msg('注销成功')
								uni.clearStorage()
								setTimeout(() => {
									uni.reLaunch({
										url: '/pages/user/public/login'
									})
								}, 200)
							}
						}
					});
					return
				}
				if (url == 'wx') {
					location.href = this.$wxLogin
				}
				uni.navigateTo({
					url
				})
			},
			//重新获取用户信息
			getInfo() {
				this.$fun.ajax.post('user/index', {}).then(res => {
					this.userInfo = res.data
					this.balance = res.data.balance
					res.data.openid ? this.msg = "已绑定" : this.msg = "未绑定"
				})
			},
			//退出登录
			toLogout() {
				uni.showModal({
					content: '确定要退出登录么',
					success: (e) => {
						if (e.confirm) {
							this.$fun.msg('退出成功')
							uni.clearStorage()
							setTimeout(() => {
								uni.reLaunch({
									url: '/pageA/public/login'
								})
							}, 200)
						}
					}
				});
			},
			//switch
			switchChange(e) {
				let statusTip = e.detail.value ? '打开' : '关闭';
				this.$api.msg(`${statusTip}消息推送`);
			},

		}
	}
</script>

<style lang='scss'>
	.account_change {
		width: 100%;
		text-align: center;
		position: absolute;
		bottom: 50rpx;
		left: 0;
		right: 0;
		margin: auto;
		color: rgb(0, 122, 255);
	}

	page {
		background: #f5f5f5;
		;
	}

	.list-cell {
		display: flex;
		align-items: baseline;
		padding: 20upx 32upx;
		line-height: 60upx;
		position: relative;
		background: #fff;
		justify-content: center;

		&.log-out-btn {
			margin-top: 40upx;

			.cell-tit {
				color: #333333;
				text-align: center;
				margin-right: 0;
				font-size: 20rpx;
			}
		}

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		&.m-t {
			margin-top: 16upx;
		}

		.cell-more {
			align-self: baseline;
			font-size: 26upx;
			color: #909399;
			margin-left: 10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: 30rpx;
			color: #333333;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: 30rpx;
			color: #333333;
			margin-right: 10upx;
		}

		switch {
			transform: translateX(16upx) scale(.84);
		}
	}

	.bq {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 130rpx;
		margin: auto;

		view {
			text-align: center;
		}
	}

	/* 退出登录 */
	.quit-login {
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 100rpx;
		background: #FFFFFF;
		border-radius: 20rpx;

		text {
			color: #222222;
			font-size: 28rpx;
		}
	}
</style>